package com.jk.controller;

import com.jk.entity.Consignee;
import com.jk.entity.MyInfoEntity;
import com.jk.entity.User;
import com.jk.entity.User1;
import com.jk.service.LoginService;
import com.jk.utils.OSSUtil;
import com.jk.utils.ValidateCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
public class LoginController {

   @Autowired
   private LoginService loginService;

    @RequestMapping( "loginUser")
    @ResponseBody
    public Map login(User user, HttpServletRequest request){
        return  loginService.login(user,request);
    }

    @RequestMapping("code")
    public void code(HttpServletRequest request, HttpServletResponse response){
        ValidateCode.createCode(request,response);
    }

    @RequestMapping("addUser")
    public  Map addUser(User1 user1, HttpServletRequest request){
        return   loginService.addUser(user1,request);
    }

   /* @RequestMapping("checkUserName")
    public  void checkUserName(String userName , HttpServletRequest request){
        loginService.checkUserName(userName,request);
    }*/

    @RequestMapping("postCode")
    @ResponseBody
    public Map postCode(String phone){
        return loginService.postCode(phone);
    }

    @RequestMapping("doLogin")
    @ResponseBody
    public Map doLogin(String phone,String code){
        return loginService.doLogin(phone,code);
    }

  @RequestMapping("checkUserName")
    public  Map checkUserName(String userName){
        return  loginService.checkUserName(userName);
  }

    @ResponseBody
    @RequestMapping("myInfo")
    public MyInfoEntity myInfo(String userName,HttpServletRequest request){
        return  loginService.myInfo(userName,request);
    }
    @ResponseBody
    @RequestMapping("chakan")
    public MyInfoEntity chakan(String userName,HttpServletRequest request){
        return  loginService.chakan(userName,request);
    }
    @RequestMapping("upMyinfo")
    public void upMyinfo(MyInfoEntity myInfoEntity,HttpServletRequest request){
          loginService.upMyinfo(myInfoEntity,request);
    }
    @RequestMapping("upload")
    @ResponseBody
    public Map upload(MultipartFile file, HttpServletRequest request) throws Exception{
        System.out.println(file);
        String upload2oss = OSSUtil.upload2oss(file);
        request.getSession().setAttribute("img", upload2oss);
        Map map=new HashMap<>();
        map.put("upload2oss", upload2oss);
        return map;
    }
    @ResponseBody
    @RequestMapping("chakanDing")
    public Consignee chakanDing(MyInfoEntity myInfoEntity, HttpServletRequest request){
         return  loginService.chakanDing(myInfoEntity,request);
    }

    @RequestMapping("shanDi")
    public void shanDi(Integer  consignee_id){
        loginService.shanDi(consignee_id);
    }

    @RequestMapping("addressMy")
    public void addressMy(Consignee con,HttpServletRequest request){
        loginService.addressMy(con,request);
    }

}
